package shop

import (
	"context"
	"fast-boot/app/api/admin/internal/svc"
	"fast-boot/app/api/admin/internal/types"
	"fast-boot/app/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type BrandOptionsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// Brand下拉列表
func NewBrandOptionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BrandOptionsLogic {
	return &BrandOptionsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BrandOptionsLogic) BrandOptions(req *types.BrandGetReq) ([]*types.BrandOption, error) {
	r := make([]*types.BrandOption, 0)
	m := model.PmsBrandModel{}
	if err := l.svcCtx.GormClient.GormDb.Model(m).
		Scopes(m.WithShopId(req.Id)).
		Select("id as value", "name as label ").
		Order("sort asc ,id asc ").
		Scan(&r).Error; err != nil {
		return nil, err
	}

	return r, nil
}
